home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Tech Arsenal 1
/
Tech Arsenal (Arsenal Computer).ISO
/
tek-01
/
inkey4c.zip
/
KEYDEMO.C
< prev
next >
Wrap
C/C++ Source or Header
|
1993-03-17
|
9KB
|
303 lines
/* _______________________________________________________________________ */
/* INKEY Test version 1.01 */
/* Copyright 1993 by John H. Traphofner */
/* _______________________________________________________________________ */
#include <stdio.h>
#include <conio.h>
#include <dos.h>
#include "inkey.h" /* If inkey.h header file is not located in your
default include directory, change this line. */
#define ON 1 /* To make the cursor(ON) and cursor(OFF) readable */
#define OFF 0
void cursor(char toggle); /* Function to turn cursor on and off */
void status_display(); /* Function to display self-updating status
screen for the key toggle switches */
void fkey_music(); /* Function to display menu of function keys
for making sounds with F1 - F12 */
void psound(int,int); /* Function to Make sound (freq, length) */
#define SUPERQUICK 16 /* Used to make KEY_WAIT length values more */
#define QUICK 256 /* readable With SUPERQUICK, the key better */
#define NORMAL 1024 /* be there when you ask for it. With the */
#define SLOW 2048 /* SLOW, there is little chance of missing it */
#define FOREVER 0 /* and FOREVER waits and waits and waits... */
int FINISHED =0; /* Global variable that either of the two main
functions (status_display) or (fkey_music) can
set to tell the main routine the user wants to
end the entire program. */
/* _______________________________________________________________________ */
/* MAIN ROUTINE */
/* _______________________________________________________________________ */
void main ()
{
cursor(OFF);
do
{
KEY_WAIT=QUICK;
status_display(); /* Display key Toggle Status */
if(FINISHED==0) fkey_music(); /* Display F-key menu if the
FINISHED variable is false */
} while ( !FINISHED );
cursor(ON); /* Restore the cursor before leaving */
clrscr(); /* and clear the screen */
return;
}
/* _______________________________________________________________________ */
/* _______________________________________________________________________ */
/* Function to turn cursor on and off */
/* _______________________________________________________________________ */
void cursor(char toggle)
{
static char c_start;
static char c_end;
if(!toggle)
{
asm mov ah,3 /* Bios call for cursor lines */
asm mov bh,0 /* page 0 */
asm int 10h /* _CH = begin scan line */
c_start = _CH; /* _CL = end scan line */
c_end = _CL; /* store for the restoring */
asm mov cl,0 /* end scan */
asm mov ch,20 /* before it begins */
asm mov ah,1 /* set the lines */
asm int 10h /* and cursor vanishes */
}
else
{
asm mov ch,c_start /* restore the old scan start */
asm mov cl,c_end /* and the old scan end */
asm mov ah,1 /* set the lines */
asm int 10h /* its BACK ! Cusror is On */
}
printf(" \b");
return;
}
/* _______________________________________________________________________ */
/* _______________________________________________________________________ */
/* Function to make some noise throught the PC Speaker */
/* _______________________________________________________________________ */
void psound(int xnote, int xtime)
{
int psx;
sound (xnote);
delay (xtime-30);
for(psx=xtime+30;psx>=1;psx--){sound (xnote-1);}
nosound();
return;
}
/* _______________________________________________________________________ */
/* _______________________________________________________________________ */
/* Function to display contiually updated toggle key status screen */
/* _______________________________________________________________________ */
void status_display()
{
static int KB101 = 255;
if (KB101==255) KB101=inkey(STATUS);
clrscr();
printf ("\n\t\t\t╔═════════════════════════════╗");
if(KB101)
printf("\n\t\t\t║ Extended 101 keyboard. ║");
else
printf("\n\t\t\t║ 84-Key PC keyboard. ║");
printf("\n\t\t\t╠═════════════════════════════╣");
printf("\n\t\t\t║ KEYBOARD STATUS ║");
printf("\n\t\t\t╠═════════════════════════════╣");
do
{
gotoxy(1,6);
FINISHED =1;
KEY_WAIT = SUPERQUICK;
if(inkey(PGDN)){FINISHED=0;break;}
if(inkey(INS_ON))
printf ("\n\t\t\t║ Insert STATUS ON ║");
else
printf ("\n\t\t\t║ Insert STATUS OFF ║");
if(inkey(CAPSLOCK_ON))
printf ("\n\t\t\t║ CAPSLOCK STATUS ON ║");
else
printf ("\n\t\t\t║ capsLock STATUS OFF ║");
if(inkey(NUMLOCK_ON))
printf ("\n\t\t\t║ NumLock STATUS ON !║");
else
printf ("\n\t\t\t║ NumLock STATUS OFF ║");
if(KB101)
{
printf("\n\t\t\t╠═════════════════════════════╣");
if(inkey(L_CTRL_PRESSED))
printf ("\n\t\t\t║ Left CTRL is PRESSED ║");
else
printf ("\n\t\t\t║ Left CTRL NOT pressed ║");
if(inkey(R_CTRL_PRESSED))
printf ("\n\t\t\t║ Right CTRL is PRESSED ║");
else
printf ("\n\t\t\t║ Right CTRL NOT pressed ║");
if(inkey(L_ALT_PRESSED))
printf ("\n\t\t\t║ Left ALT is PRESSED ║");
else
printf ("\n\t\t\t║ Left ALT NOT pressed ║");
if(inkey(R_ALT_PRESSED))
printf ("\n\t\t\t║ Right ALT is PRESSED ║");
else
printf ("\n\t\t\t║ Right ALT NOT pressed ║");
if(inkey(NUMLOCK_PRESSED))
printf ("\n\t\t\t║ Numlock is PRESSED ║");
else
printf ("\n\t\t\t║ Numlock NOT pressed ║");
if(inkey(SCROLL_PRESSED))
printf ("\n\t\t\t║ Scroll-Lock is PRESSED ║");
else
printf ("\n\t\t\t║ Scroll-Lock NOT pressed ║");
if(inkey(CAPSLOCK_PRESSED))
printf ("\n\t\t\t║ CapsLock is PRESSED ║");
else
printf ("\n\t\t\t║ CapsLock NOT pressed ║");
}
printf("\n\t\t\t╚═════════════════════════════╝");
printf("\n\n\n\t\t Press CTRL-ALT-Q to exit program");
printf("\n\t\t Press PGDN to go to next screen");
KEY_WAIT = QUICK;
/* This loop will continue while NOT CTRL and ALT-Q being pressed */
}while ( ! (inkey(CTRL_PRESSED) && inkey(ALT_Q) ) );
return;
}
/* _______________________________________________________________________ */
/* _______________________________________________________________________ */
/* Function to display function key menu for playing sounds with F1 - F12
/* _______________________________________________________________________ */
void fkey_music()
{
unsigned int keyio;
clrscr();
FINISHED=1;
printf("\n\n");
printf("\n\t\t ╔══════════════════════════════════╗");
printf("\n\t\t ╠══════════════════════════════════╣");
printf("\n\t\t ║ MUSICAL FUNCTION KEYS ║");
printf("\n\t\t ╠══════════════════════════════════╣");
printf("\n\t\t ╚══════════════════════════════════╝");
printf("\n\n");
printf("\n ▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌");
printf("\n ▌▌╔══════╗▌▌▌╔══════╗▌▌▌╔══════╗▌▌▌╔══════╗▌▌▌╔══════╗▌▌▌╔══════╗▌▌");
printf("\n ▌▌║ F1 ║▌▌▌║ F2 ║▌▌▌║ F3 ║▌▌▌║ F4 ║▌▌▌║ F5 ║▌▌▌║ F6 ║▌▌");
printf("\n ▌▌╚══════╝▌▌▌╚══════╝▌▌▌╚══════╝▌▌▌╚══════╝▌▌▌╚══════╝▌▌▌╚══════╝▌▌");
printf("\n ▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌");
printf("\n ▌▌╔══════╗▌▌▌╔══════╗▌▌▌╔══════╗▌▌▌╔══════╗▌▌▌╔══════╗▌▌▌╔══════╗▌▌");
printf("\n ▌▌║ F7 ║▌▌▌║ F8 ║▌▌▌║ F9 ║▌▌▌║ F10 ║▌▌▌║ F11 ║▌▌▌║ F12 ║▌▌");
printf("\n ▌▌╚══════╝▌▌▌╚══════╝▌▌▌╚══════╝▌▌▌╚══════╝▌▌▌╚══════╝▌▌▌╚══════╝▌▌");
printf("\n ▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌");
printf("\n\n\t\t Press Cntl-Alt-F when Finished");
printf("\n\n\t\t PGUP - to return to Status Display");
do
{
KEY_WAIT = FOREVER;
keyio=(inkey(READ_KEY));
switch(keyio)
{
case F1: psound(200,200);
break;
case F2: psound(250,200);
break;
case F3: psound(300,200);
break;
case F4: psound(350,200);
break;
case F5: psound(400,220);
break;
case F6: psound(450,220);
break;
case F7: psound(500,220);
break;
case F8: psound(550,220);
break;
case F9: psound(600,230);
break;
case F10:psound(650,230);
break;
case F11:psound(700,230);
break;
case F12:psound(750,240);
break;
case PGUP:
break;
}
if( keyio == (PGUP)){FINISHED=0; break;}
KEY_WAIT = NORMAL;
/* This loop will continue while NOT CTRL and ALT-F being pressed */
}while ( ! (inkey(CTRL_PRESSED) && inkey(ALT_F) ) );
clrscr();
return;
}